package com.twu.biblioteca;

import java.io.BufferedReader;
import java.io.IOException;

/**
 * Created by csuarez on 04/02/14.
 */
public class InputHandler {

    private BufferedReader bufferedReader;
    private Librarian librarian;

    public InputHandler(BufferedReader reader, Librarian librarian){
        this.bufferedReader = reader;
        this.librarian = librarian;
    }

    public String getInput() {
        try {
            String input = bufferedReader.readLine();
            return input;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "";
    }

    public void logInPrompt() {
        boolean isLogIn = false;

        while(isLogIn == false){
            System.out.println("Please enter your UserID and Password");

            String userID = getInput();
            String password = getInput();

            isLogIn = librarian.logInUser(userID, password);
        }
    }

    public String mainMenu() {
        if(librarian.getCurrentUser() == null){
            return "What would you like to do?(List Books/List Movies/Check In/Check Out):";
        }else{
            return "What would you like to do?(List Books/List Movies/Check In/Check Out/See my information):";
        }
    }

    public void checkInPrompt(Library library) {
        boolean checkInSuccess = false;

        while(checkInSuccess == false) {
            System.out.println("What would you like to return?");
            String title = getInput();

            checkInSuccess = library.checkIn(title, librarian.getCurrentUser());
            if(checkInSuccess) {
                System.out.println("Thanks you for returning it!");
            }else{
                System.out.println("Select a valid option");
            }
        }

    }

    public void checkOutPrompt(Library library) {
        boolean checkOutSuccess = false;

        while(checkOutSuccess == false) {
            System.out.println("What item do you want?");
            String title = getInput();

            checkOutSuccess = library.checkOut(title, librarian.getCurrentUser());
            if(checkOutSuccess) {
                System.out.println("Thanks enjoy it!");
            }else{
                System.out.println("Select a valid option");
            }
        }
    }
}
